createAPI.js ➔ ???   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
c 2
b 0
f 0
nc 1
dl 0
loc 29
rs 8.8571
nop 4

1 Function

Rating   Name   Duplication   Size   Complexity  
B createAPI.js ➔ ... ➔ ??? 0 24 1
1
import callAPIMethod from './callAPIMethod';
2
3
import applyMiddleware from './applyMiddleware';
4
5
const createAPI = (
6
    resources = {},
7
    middleware = [],
8
    APINamespace,
9
    fetchOptions
10
) => Object.keys(resources).reduce( (api, resourceId) => {
11
    api[resourceId] = Object.keys(resources[resourceId].methods)
12
        .reduce( (resource, method) => {
13
            resource[method] = (params, methodOptions) => {
14
                const apiParams = resources[resourceId].methods[method](params);
15
                const boundCallAPIMethod = callAPIMethod.bind(
16
                    null,
17
                    APINamespace,
18
                    fetchOptions,
19
                    (resources[resourceId].namespace || resources[resourceId].prefix)
20
                );
21
                return applyMiddleware(
22
                    boundCallAPIMethod,
23
                    middleware,
24
                    methodOptions,
25
                    apiParams,
26
                    resourceId,
27
                    method
28
                );
29
            };
30
            return resource;
31
        }, {});
32
    return api;
33
}, {});
34
35
export default createAPI;
36